package cn.stylefeng.guns.sys.modular.dbServicelist.controller;

import cn.stylefeng.guns.base.auth.context.LoginContextHolder;
import cn.stylefeng.guns.base.auth.model.LoginUser;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.dbServicelist.model.params.DbServicelistParam;
import cn.stylefeng.guns.sys.modular.dbServicelist.service.DbServicelistService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;

/**
 * @author shkstart
 * @create 2020-08-24 10:23
 */
@Controller
@RequestMapping("/expiredListKh")
public class DbServicelistTimeOutController extends BaseController {

    private String PREFIX = "/modular/dbServicelistTimeOut";

    @Autowired
    private DbServicelistService dbServicelistService;

    /**
     * 过期及废弃列表
     *
     * @author zhaoyiheng
     * @Date 2020-08-19
     */
    @RequestMapping("")
    public String edit() {
        return PREFIX + "/dbServicelistTimeOut.html";
    }


    /**
     * 查询列表
     *
     * @author zhaoyiheng
     * @Date 2020-08-19
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(DbServicelistParam dbServicelistParam) throws ParseException {
        return this.dbServicelistService.findPageBySpecTime(dbServicelistParam);
    }


    /**
     * 申请下架
     *
     * @author zhaoyiheng
     * @Date 2020-08-19
     */
    @ResponseBody
    @RequestMapping("/offShelf")
    public ResponseData offShelf(DbServicelistParam dbServicelistParam) throws ParseException {
        this.dbServicelistService.offShelf(dbServicelistParam);
        return ResponseData.success();
    }


    /**
     * 申请下架
     *
     * @author zhaoyiheng
     * @Date 2020-08-19
     */
    @ResponseBody
    @RequestMapping("/active")
    public ResponseData active(DbServicelistParam dbServicelistParam) throws ParseException {
        LoginUser user = LoginContextHolder.getContext().getUser();
        this.dbServicelistService.active(dbServicelistParam,user);
        return ResponseData.success();
    }
}
